/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.omega_r.omegarecyclerview.pagination_example;

import com.omega_r.libs.omegarecyclerview.base.BaseBean;
import com.omega_r.libs.omegarecyclerview.base.BaseViewHolder;
import com.omega_r.omegarecyclerview.ResourceTable;
import com.omega_r.omegarecyclerview.swipe_menu_example.Contacts;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.components.*;
import ohos.agp.components.Image;
import ohos.agp.window.dialog.ToastDialog;

public class ImageViewHolder extends BaseViewHolder {
    private Image imageView;
    private int position;

    public ImageViewHolder(Component parent) {
        super(parent);
        imageView = (Image) findComponentById(ResourceTable.Id_imageview);
        imageView.setClickedListener(this);
    }

    @Override
    public void updateView(BaseBean baseBean) {
        this.updateView(baseBean,0);
    }

    public void updateView(BaseBean baseBean,int position) {
        super.updateView(baseBean);
        this.position=position;
        com.omega_r.omegarecyclerview.pagination_example.Image image = (com.omega_r.omegarecyclerview.pagination_example.Image) baseBean;
        imageView.setPixelMap(image.getImageRes());
    }

    @Override
    public void onClick(Component component) {
        super.onClick(component);
        switch (component.getId()) {
            case ResourceTable.Id_imageview:
                showToast("Clicked "+position);
                break;
        }
    }
    /**
     * Toast弹框
     *
     * @param content 内容
     */
    private void showToast(String content) {
        Component toastLayout = LayoutScatter.getInstance(itemView.getContext())
                .parse(ResourceTable.Layout_layout_toast, null, false);
        Text toastText = (Text) toastLayout.findComponentById(ResourceTable.Id_text_msg_toast);
        toastText.setText(content);
        new ToastDialog(itemView.getContext())
                .setComponent(toastLayout)
                .setTransparent(true)
                .show();
    }
}
